#include "CCharacters.h"

CCharacters::CCharacters()
{
    this->message_box = new QMessageBox();
    this->c_database = new CDataBase;
    this->c_network = new CNetwork;
}

CCharacters::~CCharacters()
{
    delete this->message_box;
}

void CCharacters::get_characters(MClient* client)
{
    client->set_characters(this->c_database->get_characters(client));

    //c_network->send(client->get_socket(), "start_characters");
    foreach(MCharacter* c, client->get_characters())
    {

        c_network->send(client->get_socket(), QString::number(c->get_id()));
        c_network->send(client->get_socket(), c->get_username());
        c_network->send(client->get_socket(), c->get_map_ip());
        c_network->send(client->get_socket(), c->get_map_name());
        c_network->send(client->get_socket(), c->get_map_port());
        c_network->send(client->get_socket(), QString::number(c->get_level()));
        c_network->send(client->get_socket(), QString::number(c->get_exp()));
        c_network->send(client->get_socket(), c->get_bonus());
    }

    message_box->setText("id : "+QString::number(client->get_characters().at(0)->get_id()));
    message_box->setText(message_box->text()+"username : "+client->get_characters().at(0)->get_username());
    message_box->setText(message_box->text()+"ip : "+client->get_characters().at(0)->get_map_ip());
    message_box->setText(message_box->text()+"name : "+client->get_characters().at(0)->get_map_name());
    message_box->setText(message_box->text()+"port : "+client->get_characters().at(0)->get_map_port());
    message_box->setText(message_box->text()+"level : "+QString::number(client->get_characters().at(0)->get_level()));
    message_box->setText(message_box->text()+"exp : "+QString::number(client->get_characters().at(0)->get_exp()));
    message_box->setText(message_box->text()+"bonus : "+client->get_characters().at(0)->get_bonus());
    //message_box->show();
}
